﻿using System;
using System.Runtime.InteropServices;
using System.Text;

namespace Generator
{

    public class WindowsHookHelper
    {
        [DllImport("User32.dll")]
        public extern static IntPtr CallNextHookEx(IntPtr hHook, int nCode, IntPtr wParam, IntPtr lParam);

        [DllImport("User32.dll")]
        public extern static IntPtr UnhookWindowsHookEx(IntPtr hHook);

        [DllImport("User32.dll")]
        public extern static IntPtr SetWindowsHookEx(int idHook, WindowsHookHelper.HookDelegate lpfn, IntPtr hmod, int dwThreadId);


        [DllImport("user32.dll")]
        public extern static IntPtr GetForegroundWindow();

        [DllImport("user32.dll")]
        public extern static IntPtr WindowFromPoint(POINT Point);

        [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        public extern static int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);

        //[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true, EntryPoint = "GetWindowTextA")]
        //public extern static int GetWindowText(IntPtr hWnd, string lpString, long nMaxCount);

        [DllImport("User32.dll")]
       public  static extern int GetWindowText(IntPtr handle, StringBuilder text, int MaxLen);


        //     Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" _
        //(ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) _
        // As Long


        public delegate IntPtr HookDelegate(int Code, IntPtr wParam, IntPtr lParam);
    }

    public struct POINT
    {
        public int x;
        public int y;
    }
}
